package com.tfjybj.itoo.teach.provider.controller;

import com.dmsdbj.itoo.tool.business.ItooResult;
import com.github.pagehelper.PageInfo;
import com.tfjybj.itoo.teach.entity.TeacherTeachClassEntity;
import com.tfjybj.itoo.teach.model.TeacherTeachClassModel;
import com.tfjybj.itoo.teach.provider.service.TeacherTeachClassService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


/**
 * TeacherTeachClassController
 * teacherTeachClass表
 *
 * @author 田成荣
 * @version 2.0.0
 * @since 2.0.0 2018-11-08 19:34:10
 */
@Api(tags = {"teacherTeachClass表接口"})
@RequestMapping(value = "/teacherTeachClass")
@RestController
@Slf4j
public class TeacherTeachClassController {

    @Resource
    private TeacherTeachClassService teacherTeachClassService;

    //region 模板生成：基本增删改

    /**
     * 添加
     *
     * @param model TeacherTeachClassModel
     * @return 添加的结果
     * @author 田成荣
     * @since 2.0.0 2018-11-08 19:34:10
     */
    @ApiOperation(value = "添加")
    @PostMapping(value = {"/create"})
    public ItooResult create(@RequestBody TeacherTeachClassModel model) {
		if (StringUtils.isEmpty(model.getTeachClassId())){
            return ItooResult.build(ItooResult.FAIL, "teachClassId为空");
        }
		if (StringUtils.isEmpty(model.getTeacherId())){
            return ItooResult.build(ItooResult.FAIL, "teacherId为空");
        }
        TeacherTeachClassEntity teacherTeachClassEntity = new TeacherTeachClassEntity();
        BeanUtils.copyProperties(model, teacherTeachClassEntity);
        teacherTeachClassService.save(teacherTeachClassEntity);
        return ItooResult.build(ItooResult.SUCCESS, "添加成功");
    }

    /**
     * 删除
     *
     * @param id 主键id
     * @return ItooResult 是否删除成功          
     * @author 田成荣
     * @since 2.0.0 2018-11-08 19:34:10
     */
    @ApiOperation(value = "根据id删除（单个）")
    @DeleteMapping(value = {"/delete/{id}"})
    public ItooResult delete(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        teacherTeachClassService.removeById(id);
        return ItooResult.build(ItooResult.SUCCESS, "删除成功");
    }

    /**
     * 批量删除
     *
     * @param ids ids
     * @return ItooResult 批量删除是否成功结果
     * @author 田成荣
     * @since 2.0.0 2018-11-08 19:34:10
     */
    @ApiOperation(value = "根据id批量删除")
    @DeleteMapping(value = {"/deleteByIds"})
    @ApiImplicitParam(name = "ids", value = "ids", dataType = "List<String>", required = true)
    public ItooResult deleteByIds(@RequestBody List<String> ids) {
        teacherTeachClassService.removeByIds(ids);
        return ItooResult.build(ItooResult.SUCCESS, "批量删除成功");
    }

    /**
     * 修改
     *
     * @param model TeacherTeachClassModel
     * @return 修改后的结果
     * @author 田成荣
     * @since 2.0.0 2018-11-08 19:34:10
     */
    @ApiOperation(value = "根据id修改teacherTeachClass")
    @PutMapping(value = {"/modify"})
    public ItooResult modify(@RequestBody TeacherTeachClassModel model) {
		if (StringUtils.isEmpty(model.getTeachClassId())){
            return ItooResult.build(ItooResult.FAIL, "teachClassId为空");
        }
		if (StringUtils.isEmpty(model.getTeacherId())){
            return ItooResult.build(ItooResult.FAIL, "teacherId为空");
        }
        TeacherTeachClassEntity teacherTeachClassEntity = new TeacherTeachClassEntity();
        BeanUtils.copyProperties(model, teacherTeachClassEntity);
        teacherTeachClassService.updateById(teacherTeachClassEntity);
        return ItooResult.build(ItooResult.SUCCESS, "修改成功");
    }

    /**
     * 根据id查找TeacherTeachClass
     *
     * @param id 主键id
     * @author 田成荣
     * @since 2.0.0 2018-11-08 19:34:10
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = {"/findById/{id}"})
    public ItooResult findById(@ApiParam(value = "主键id", required = true) @PathVariable String id) {
        TeacherTeachClassEntity teacherTeachClassEntity = teacherTeachClassService.getById(id);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", teacherTeachClassEntity);
    }

    /**
     * 分页查询所有TeacherTeachClass
     *
     * @param pageNo   页码
     * @param pageSize 每页条数
     * @author 田成荣
     * @since 2.0.0 2018-11-08 19:34:10
     */
    @ApiOperation(value = "分页查询所有TeacherTeachClass")
    @GetMapping(value = {"/queryPageAll/{pageNo}/{pageSize}"})
    public ItooResult queryPageAll(@ApiParam(name = "pageNo",value = "页码",required = true,example = "1")@PathVariable Integer pageNo,
                                   @ApiParam(name = "pageSize",value = "页数",required = true,example = "10")@PathVariable Integer pageSize) {
        PageInfo<TeacherTeachClassEntity> teacherTeachClasss = teacherTeachClassService.queryPageAll(pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", teacherTeachClasss);
    }
	
	/**
     * 根据上课班id模糊查询teacherTeachClass
     *
     * @param teachClassId  上课班id
     * @param pageNo   页码
     * @param pageSize 页数
     * @return 模糊查询的teacherTeachClass
     * @author 田成荣
     * @since 2.0.0 2018-11-08 19:34:10
     */
    @ApiOperation(value = "根据上课班id模糊查询teacherTeachClass", notes = "分页根据上课班id模糊查询teacherTeachClass")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "页码", dataType = "int", required = true, example = "1"),
            @ApiImplicitParam(name = "pageSize", value = "记录数", dataType = "int", required = true, example = "10")
    })
    @GetMapping(value = "queryTeacherTeachClassByLikeTeachClassId/{pageNo}/{pageSize}")
    public ItooResult queryTeacherTeachClassByLikeTeachClassId(@RequestParam(required = false, defaultValue = "") String teachClassId,
                                                               @PathVariable Integer pageNo, @PathVariable Integer pageSize) {
        PageInfo<TeacherTeachClassEntity> teacherTeachClassList = teacherTeachClassService.queryByLikeTeachClassId(teachClassId, pageNo, pageSize);
        return ItooResult.build(ItooResult.SUCCESS, "查询成功", teacherTeachClassList);
    }
    //endregion

    /* **********************************以下为非模板生成的内容********************************* */

    /**
     * 根据上课班id查询学生信息
     * @param teachClassId
     * @return 学生信息list
     * @author 郝雨烁
     * @since 0.0.1 2019年3月6日16:34:48
     */
    @ApiOperation(value = "根据上课班id查询学生信息")
    @GetMapping(value = {"/queryStudents/{teachClassId}"})
   public ItooResult queryStudents(@ApiParam(value = "上课班id", required = true)@PathVariable String teachClassId){
       if(StringUtils.isEmpty(teachClassId)){
           log.warn("上课班id不能为空");
           return ItooResult.build(ItooResult.FAIL,"查询失败");
       }
       return ItooResult.build(ItooResult.SUCCESS,"查询成功",teacherTeachClassService.queryStudents(teachClassId));
   }

    /**
     * 根据教师id查询上课班信息-郄子硕-2019-3-7 19:59:00
     * @param teacherId 教师Id
     * @return 上课班Model
     */
    @ApiOperation(value = "根据教师id查询上课班信息")
    @GetMapping(value = {"/queryTeachClass/{teacherId}"})
    public ItooResult queryTeachClass(@ApiParam(value = "教师id", required = true)@PathVariable String teacherId){
        if(StringUtils.isEmpty(teacherId)){
            log.warn("教师Id不能为空");
            return ItooResult.build(ItooResult.FAIL,"查询失败");
        }
        return ItooResult.build(ItooResult.SUCCESS,"查询成功",teacherTeachClassService.queryTeachClass(teacherId));
    }


}
